﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL
{
    public sealed partial class AnalysisEngine
    {
        /// <summary>
        /// 标准差
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static decimal StandardDeviation(IEnumerable<decimal> input)
        {
            decimal average = input.Average();

            var helperList = new List<decimal>();

            for (int i = 0; i < input.Count(); i++)
            {
                helperList.Add((decimal)Math.Pow((double)(input.ElementAt(i) - average), 2));
            }

            return (decimal)Math.Sqrt((double)(helperList.Sum() / helperList.Count()));
        }
    }
}
